/**
 * Copyright 2016 Google Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

// DO NOT EDIT THIS GENERATED OUTPUT DIRECTLY!
// This file should be overwritten as part of your build process.
// If you need to extend the behavior of the generated service worker, the best approach is to write
// additional code and include it using the importScripts option:
//   https://github.com/GoogleChrome/sw-precache#importscripts-arraystring
//
// Alternatively, it's possible to make changes to the underlying template file and then use that as the
// new base for generating output, via the templateFilePath option:
//   https://github.com/GoogleChrome/sw-precache#templatefilepath-string
//
// If you go that route, make sure that whenever you update your sw-precache dependency, you reconcile any
// changes made to this original template file with your modified copy.

// This generated service worker JavaScript will precache your site's resources.
// The code needs to be saved in a .js file at the top-level of your site, and registered
// from your pages in order to be used. See
// https://github.com/googlechrome/sw-precache/blob/master/demo/app/js/service-worker-registration.js
// for an example of how you can register this script and handle various service worker events.

/* eslint-env worker, serviceworker */
/* eslint-disable indent, no-unused-vars, no-multiple-empty-lines, max-nested-callbacks, space-before-function-paren, quotes, comma-spacing */
'use strict';

var precacheConfig = [["404.html","f1ec8a6ce7e3e0d33e9a5f501eb04d9e"],["about/index.html","df61f468abe7ad65cb33b667d618e167"],["archives/2020/05/index.html","a89a39f4107f563eaf41d7d013512ce7"],["archives/2020/05/page/2/index.html","3043e14a0f3c9ca40d69f6e309c5a2e3"],["archives/2020/06/index.html","da453b4a65cbcf1c539a632e9f508a2f"],["archives/2020/07/index.html","de7db0658a478326542f94c8fde00a2b"],["archives/2020/11/index.html","d917c6e847a4e497773a84393a2d1139"],["archives/2020/12/index.html","a087b36dde5dc4b0891c8bb236225870"],["archives/2020/index.html","b0293229b84426966e41407988cd812f"],["archives/2020/page/2/index.html","0629e3778cd1879e1208afe9d5b161bb"],["archives/2021/01/index.html","7c603af8c95777ced438c4eaecd603cb"],["archives/2021/index.html","ea5c256c2951a40843b06a1ec7842a5c"],["archives/index.html","d77dc1a0b9f8db5b0336ff1b41b8a86f"],["archives/page/2/index.html","d77dc1a0b9f8db5b0336ff1b41b8a86f"],["categories/Hexo博客/index.html","6513de5a7c5ae108e8455952b0476c00"],["categories/index.html","aa16a9a9700eee468f2cb8a9c4c8e052"],["categories/前端/React/index.html","d8dea4a89a26efffd1af8bec58170ad5"],["categories/前端/TypeScript/index.html","d0a677550edc04340f6f77153026d92e"],["categories/前端/index.html","41175ba6d4be11663c0bf3a3e540bb34"],["categories/前端/page/2/index.html","0617a7f51a5e680434874678aa1b1562"],["categories/前端/webpack4-0学习总结/index.html","004a9a8fedd35b90b312a295709e828f"],["categories/前端/工作/index.html","a3c00d9b97a46bb86508bf5d1862f6e1"],["categories/前端/面试造轮/index.html","1a42882e0373d9bf1ad9f059df49bdc2"],["categories/效率工具/index.html","8163b4788a2322e8ac39ebd9189a3057"],["categories/测试分类/index.html","c34dded584c39f2e3a3176b6171e7cb2"],["categories/记录生活/2020/index.html","be22ac8b8312416451dd3af843d6ef51"],["categories/记录生活/index.html","b7aa5527146a765a9b7461a407e6881d"],["css/first.css","0dad0ae9830231c52dfbc1a1f739f027"],["css/style.css","2417f18c2b7d1674f39e97f273536641"],["friends/index.html","e126042ae3ecea21e347c1f509a48be2"],["index.html","5fd58521e1f300ba7b2e0ef21759b0c4"],["js/aplayer.js","f4d6fd12b69098d117f65cc0f1371a3d"],["js/app.js","a362aa73726a74b62ade3edf7a5dde65"],["js/issues.js","31c43c2f323daded49b27eb8f9792476"],["js/search.js","4d3655faf8f9033e9faf5fda842a16a5"],["js/valine.js","9207fdb8d013c87dbe26fc906b40f68f"],["list/index.html","0ffdc1322463b3f796a4f86cb5a109f2"],["page/2/index.html","7dfff24e5574f769a97aa83200aba459"],["posts/20802113/index.html","0ca843204a15212a1516cdecca22e558"],["posts/24b4915a/index.html","31bec190f178ccd2113e4f3a8e3fd66e"],["posts/35b500c6/index.html","a1af42f93294713d8ecf713ecd13c3be"],["posts/3b0a6cbe/index.html","9f8c7e184104dfeea18b00e01f0f956c"],["posts/66d3b164/index.html","ac81c7454860a8627c3081dd90a9f72e"],["posts/6af865/index.html","77cd9e44942953c8b7dd16e740b4faf6"],["posts/829819a3/index.html","e2780788c9f057dafa2e1024e983a9e8"],["posts/832ac07a/index.html","e7693a61a6794dc87235f0a2066b2472"],["posts/84d16999/index.html","11f4ca303263c86c97e4660a00546e50"],["posts/92c49d45/index.html","7570a7eef0a682dd93e931ceca19be75"],["posts/b050203a/index.html","c33e1912a24b98a3831b1ad63c3ea154"],["posts/b4c78541/index.html","58fb6b4ffdb5012debc394f9b17ca163"],["posts/c05e5480/index.html","4e6bac5e31a2c358cb2dabf15849c569"],["posts/cf86baf1/index.html","14b2b741ba0da3a9929b93d3f2cc2f06"],["posts/d4ddb122/index.html","da81fcd42f71ff05c02ac5c7f517e28e"],["posts/f032f0/index.html","6af12652df87c5328c51bd3fc403ff87"],["posts/f9d92613/index.html","21ad73e89926330929f711f049ce303a"],["posts/fc7889ef/index.html","dfaf25208be20f5fe86465e110b0133f"],["posts/ff905629/index.html","31cb1c01ed0f4754723d0432d5d40aed"],["tags/DIY博客/index.html","91538ba9b7320e1bf0bf854c6a977cf5"],["tags/Hexo/index.html","842ed28f629ac6f790dd1d909db30d22"],["tags/Hexo评论系统/index.html","7dc17f9d3a2afac928df77f6ad1996a0"],["tags/Next-js/index.html","002cd6fec07070d05e0f3b2a2f3c957a"],["tags/React/index.html","e466ce78668d8170cd45457d11e60a7e"],["tags/ReactHook/index.html","1dcd3839c8825d246745637059e94d28"],["tags/TypeScript/index.html","a0aa257d8bfca1b335dfebfe25b8c406"],["tags/Typora/index.html","0ae4143518ee21b2a78055de6eb21466"],["tags/Valine国际版/index.html","14bf1cd789801a45c9785029f904bef1"],["tags/index.html","17d301aab91efc75b221e1509f814a2c"],["tags/jwt/index.html","dae86b4f2bffe777b7c87083c094ffb1"],["tags/webpack4-0/index.html","cbe802a9dd7c21d2712269942599d8d4"],["tags/博客/index.html","04911f6e22e050b25075ef17ba2bb516"],["tags/工作/index.html","eb28d669fb2c8f6b586841aeea8a61f7"],["tags/工具/index.html","53d93ce922386839970afb20a376b5ab"],["tags/测试标签/index.html","a998402bacf0be7d474c5f6b715efad6"],["tags/自动化测试/index.html","5718adaab06c18a8316a602200dfee06"],["tags/记录生活/index.html","5de401415e4c12641ab7bd661e83e7a5"],["tags/部署/index.html","19c35f05def760090e5f2816b74bb191"],["tags/阿里云/index.html","f57cb186bba48a358109702c32046c62"],["tags/面试题/index.html","caac83ea683acbcca7aae5f20f4a65ac"]];
var cacheName = 'sw-precache-v3--' + (self.registration ? self.registration.scope : '');


var ignoreUrlParametersMatching = [/^utm_/];



var addDirectoryIndex = function(originalUrl, index) {
    var url = new URL(originalUrl);
    if (url.pathname.slice(-1) === '/') {
      url.pathname += index;
    }
    return url.toString();
  };

var cleanResponse = function(originalResponse) {
    // If this is not a redirected response, then we don't have to do anything.
    if (!originalResponse.redirected) {
      return Promise.resolve(originalResponse);
    }

    // Firefox 50 and below doesn't support the Response.body stream, so we may
    // need to read the entire body to memory as a Blob.
    var bodyPromise = 'body' in originalResponse ?
      Promise.resolve(originalResponse.body) :
      originalResponse.blob();

    return bodyPromise.then(function(body) {
      // new Response() is happy when passed either a stream or a Blob.
      return new Response(body, {
        headers: originalResponse.headers,
        status: originalResponse.status,
        statusText: originalResponse.statusText
      });
    });
  };

var createCacheKey = function(originalUrl, paramName, paramValue,
                           dontCacheBustUrlsMatching) {
    // Create a new URL object to avoid modifying originalUrl.
    var url = new URL(originalUrl);

    // If dontCacheBustUrlsMatching is not set, or if we don't have a match,
    // then add in the extra cache-busting URL parameter.
    if (!dontCacheBustUrlsMatching ||
        !(url.pathname.match(dontCacheBustUrlsMatching))) {
      url.search += (url.search ? '&' : '') +
        encodeURIComponent(paramName) + '=' + encodeURIComponent(paramValue);
    }

    return url.toString();
  };

var isPathWhitelisted = function(whitelist, absoluteUrlString) {
    // If the whitelist is empty, then consider all URLs to be whitelisted.
    if (whitelist.length === 0) {
      return true;
    }

    // Otherwise compare each path regex to the path of the URL passed in.
    var path = (new URL(absoluteUrlString)).pathname;
    return whitelist.some(function(whitelistedPathRegex) {
      return path.match(whitelistedPathRegex);
    });
  };

var stripIgnoredUrlParameters = function(originalUrl,
    ignoreUrlParametersMatching) {
    var url = new URL(originalUrl);
    // Remove the hash; see https://github.com/GoogleChrome/sw-precache/issues/290
    url.hash = '';

    url.search = url.search.slice(1) // Exclude initial '?'
      .split('&') // Split into an array of 'key=value' strings
      .map(function(kv) {
        return kv.split('='); // Split each 'key=value' string into a [key, value] array
      })
      .filter(function(kv) {
        return ignoreUrlParametersMatching.every(function(ignoredRegex) {
          return !ignoredRegex.test(kv[0]); // Return true iff the key doesn't match any of the regexes.
        });
      })
      .map(function(kv) {
        return kv.join('='); // Join each [key, value] array into a 'key=value' string
      })
      .join('&'); // Join the array of 'key=value' strings into a string with '&' in between each

    return url.toString();
  };


var hashParamName = '_sw-precache';
var urlsToCacheKeys = new Map(
  precacheConfig.map(function(item) {
    var relativeUrl = item[0];
    var hash = item[1];
    var absoluteUrl = new URL(relativeUrl, self.location);
    var cacheKey = createCacheKey(absoluteUrl, hashParamName, hash, false);
    return [absoluteUrl.toString(), cacheKey];
  })
);

function setOfCachedUrls(cache) {
  return cache.keys().then(function(requests) {
    return requests.map(function(request) {
      return request.url;
    });
  }).then(function(urls) {
    return new Set(urls);
  });
}

self.addEventListener('install', function(event) {
  event.waitUntil(
    caches.open(cacheName).then(function(cache) {
      return setOfCachedUrls(cache).then(function(cachedUrls) {
        return Promise.all(
          Array.from(urlsToCacheKeys.values()).map(function(cacheKey) {
            // If we don't have a key matching url in the cache already, add it.
            if (!cachedUrls.has(cacheKey)) {
              var request = new Request(cacheKey, {credentials: 'same-origin'});
              return fetch(request).then(function(response) {
                // Bail out of installation unless we get back a 200 OK for
                // every request.
                if (!response.ok) {
                  throw new Error('Request for ' + cacheKey + ' returned a ' +
                    'response with status ' + response.status);
                }

                return cleanResponse(response).then(function(responseToCache) {
                  return cache.put(cacheKey, responseToCache);
                });
              });
            }
          })
        );
      });
    }).then(function() {
      
      // Force the SW to transition from installing -> active state
      return self.skipWaiting();
      
    })
  );
});

self.addEventListener('activate', function(event) {
  var setOfExpectedUrls = new Set(urlsToCacheKeys.values());

  event.waitUntil(
    caches.open(cacheName).then(function(cache) {
      return cache.keys().then(function(existingRequests) {
        return Promise.all(
          existingRequests.map(function(existingRequest) {
            if (!setOfExpectedUrls.has(existingRequest.url)) {
              return cache.delete(existingRequest);
            }
          })
        );
      });
    }).then(function() {
      
      return self.clients.claim();
      
    })
  );
});


self.addEventListener('fetch', function(event) {
  if (event.request.method === 'GET') {
    // Should we call event.respondWith() inside this fetch event handler?
    // This needs to be determined synchronously, which will give other fetch
    // handlers a chance to handle the request if need be.
    var shouldRespond;

    // First, remove all the ignored parameters and hash fragment, and see if we
    // have that URL in our cache. If so, great! shouldRespond will be true.
    var url = stripIgnoredUrlParameters(event.request.url, ignoreUrlParametersMatching);
    shouldRespond = urlsToCacheKeys.has(url);

    // If shouldRespond is false, check again, this time with 'index.html'
    // (or whatever the directoryIndex option is set to) at the end.
    var directoryIndex = 'index.html';
    if (!shouldRespond && directoryIndex) {
      url = addDirectoryIndex(url, directoryIndex);
      shouldRespond = urlsToCacheKeys.has(url);
    }

    // If shouldRespond is still false, check to see if this is a navigation
    // request, and if so, whether the URL matches navigateFallbackWhitelist.
    var navigateFallback = '';
    if (!shouldRespond &&
        navigateFallback &&
        (event.request.mode === 'navigate') &&
        isPathWhitelisted([], event.request.url)) {
      url = new URL(navigateFallback, self.location).toString();
      shouldRespond = urlsToCacheKeys.has(url);
    }

    // If shouldRespond was set to true at any point, then call
    // event.respondWith(), using the appropriate cache key.
    if (shouldRespond) {
      event.respondWith(
        caches.open(cacheName).then(function(cache) {
          return cache.match(urlsToCacheKeys.get(url)).then(function(response) {
            if (response) {
              return response;
            }
            throw Error('The cached response that was expected is missing.');
          });
        }).catch(function(e) {
          // Fall back to just fetch()ing the request if some unexpected error
          // prevented the cached response from being valid.
          console.warn('Couldn\'t serve response for "%s" from cache: %O', event.request.url, e);
          return fetch(event.request);
        })
      );
    }
  }
});







